package jltx.fragmentpageframework.simple.fragment.pager;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cn.jltx.utils.ViewHelper;
import jltx.fragmentpageframework.R;
import jltx.fragmentpageframework.simple.adapter.NewsTabPagerAdapter;
import jltx.fragmentpageframework.simple.fragment.base.BaseMainFragment;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/05/21.
 */

public class NewsTabFragment extends BaseMainFragment {
    private List<String> tabTitles;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private NewsTabPagerAdapter pagerAdapter;
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_simple_new_tab,container,false);
        setToolbarTitle(R.string.menu_nav_simple_tab);
        tabLayout = ViewHelper.findViewById(rootView,R.id.tab_layout_simple_tab_fragment);
        viewPager = ViewHelper.findViewById(rootView,R.id.viewpager_simple_tab_fragment);
        viewPager.setOffscreenPageLimit(5);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }


    private void initData(){
        tabTitles = new ArrayList<>();
        tabTitles.add("国内");
        tabTitles.add("国际");
        tabTitles.add("军事");
        tabTitles.add("图片");
        tabTitles.add("娱乐");
        tabTitles.add("科技");
        tabTitles.add("财经");
        tabTitles.add("汽车");
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        initData();
        pagerAdapter = new NewsTabPagerAdapter(getChildFragmentManager(),tabTitles);
        viewPager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
        super.onLazyInitView(savedInstanceState);
    }
}
